version: '3.9'

networks:
  postgres:
    driver: bridge

volumes:
  postgres: {}
  pgadmin: {}

services:
  fapi-local:
    build:
      dockerfile: Dockerfile
    container_name: fapi-local
    depends_on:
      - postgres
    networks:
      - postgres

  postgres:
    container_name: fapi_postgres_local
    image: postgres:16.2-alpine3.19
    environment:
      POSTGRES_USER: bbnf
      POSTGRES_PASSWORD: qwerty
      POSTGRES_DB: fapi_dev
    volumes:
      - ./.data/postgres:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U bbnf -d fapi_dev"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 10s
    restart: unless-stopped
    deploy:
      resources:
        limits:
          cpus: '1'
          memory: 4G

  pgadmin:
    container_name: fapi_pgadmin_container
    image: dpage/pgadmin4:latest
    user: '$UID:$GID'
    environment:
      PGADMIN_DEFAULT_EMAIL: "maks@babenoff.ru"
      PGADMIN_DEFAULT_PASSWORD: "qwerty"
      PGADMIN_CONFIG_SERVER_MODE: "False"
    volumes:
      - ./.data/pgadmin:/var/lib/pgadmin
    ports:
      - "5050:80"
    depends_on:
      - postgres
    restart: unless-stopped
    deploy:
      resources:
        limits:
          cpus: '0.5'
          memory: 1G
    networks:
      - postgres
